package com.lufei.message_system.Data.UserVD;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Data
@Schema(name = "用户创建DTO")
public class UserCreateDTO {
    @NotBlank(message = "用户号不能为空")
    @Schema(description = "用户号", requiredMode = Schema.RequiredMode.REQUIRED)
    private String userId;

    @NotBlank(message = "姓名不能为空")
    @Size(max = 50, message = "姓名长度不能超过50")
    @Schema(description = "姓名", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
    private String name;

    @Schema(description = "大学名", example = "大连民族大学")
    private String universityName;

    @Schema(description = "学院名", example = "计算机学院")
    private String collegeName;

    @Schema(description = "专业名", example = "软件工程")
    private String majorName;

    @Schema(description = "班级", example = "1001")
    private String classId;

    @Size(max = 10, message = "年级长度不能超过10")
    @Schema(description = "年级", example = "2023")
    private String grade;

    @NotBlank(message = "角色不能为空")
    @Pattern(regexp = "admin|teacher|student", message = "角色必须是admin、teacher或student")
    @Schema(description = "角色", requiredMode = Schema.RequiredMode.REQUIRED, example = "student",
            allowableValues = {"admin", "teacher", "student"})
    private String role;

    @NotBlank(message = "密码不能为空")
    @Size(min = 6, max = 20, message = "密码长度必须在6到20之间")
    @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
    private String password;

    // 验证方法
    public boolean isValidForRole() {
        if ("admin".equals(role)) {
            return userId != null && userId.matches("\\d{1,5}") &&
                    name != null && password != null;
        } else if ("teacher".equals(role)) {
            return userId != null && userId.matches("\\d{6,9}") &&
                    name != null && universityName != null &&
                    collegeName != null && majorName != null &&
                    password != null;
        } else { // student
            return userId != null && userId.matches("\\d{10,}") &&
                    name != null && universityName != null &&
                    collegeName != null && majorName != null &&
                    classId != null && grade != null &&
                    password != null;
        }
    }
}